package com.ai5suoai.ams.web.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.AbstractMessageSource;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import java.util.Locale;

import javax.annotation.Resource;

/**
 * @author chenzhenjia
 * @since 16/4/3
 */
@Component
public class MessageSourceUtil {

    @Resource(name = "messageSource")
    AbstractMessageSource messageSource;
    @Autowired
    WebApplicationContext webApplicationContext;

    public String getMessage(String key, Object[] args) {
        return messageSource.getMessage(key, args, getCurrentLocale());
    }

    public String getMessage(String key) {
        return getMessage(key, null);
    }

    /**
     * 获得当前语言的环境
     */
    public Locale getCurrentLocale() {
        return LocaleContextHolder.getLocale();
    }


}
